home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F24674_Max.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  1.8 KB  |  54 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3.     <xsl:output method="html" indent="yes"/>
  4.     <xsl:template name="Max">
  5.     
  6.         <!--This template will recursively -->
  7.         <!--determine the maximim value in a nodeset -->
  8.         
  9.         
  10.         <xsl:param name="list" />
  11.         <xsl:param name="nMax" select="'0'"/>
  12.  
  13.         <xsl:choose>
  14.             <xsl:when test="$list">
  15.  
  16.                 <!-- Store the remaining list into a variable for subsequent -->
  17.                 <!-- recursive calls to this template                        -->    
  18.                 <xsl:variable name="remainingList" select="$list[position() != 1]" />
  19.  
  20.                 <!-- Calculate the new minimum value.  The value is set to   -->
  21.                 <!-- the currently passed in value, or the value in the node -->
  22.                 <!-- set, whichever is lower                               -->    
  23.                 <xsl:variable name="nNewMax">
  24.                     <xsl:choose>
  25.                         <xsl:when test="$list[1] > $nMax">
  26.                             <xsl:value-of select="$list[1]"    />
  27.                         </xsl:when>
  28.                         <xsl:otherwise>
  29.                             <xsl:value-of select="$nMax"    />
  30.                         </xsl:otherwise>
  31.                     </xsl:choose>
  32.                 </xsl:variable>
  33.  
  34.                 <!-- Recursively call the current template with the newly      -->
  35.                 <!-- calculated minimum value                                 -->
  36.                 <xsl:call-template name="Max">
  37.                     <xsl:with-param name="list" select="$remainingList"/>
  38.                     <xsl:with-param name="nMax" select="$nNewMax"/>
  39.                 </xsl:call-template>
  40.  
  41.         </xsl:when>
  42.  
  43.         <xsl:otherwise>
  44.             <!-- If you have hit this section in the template, it indicates -->
  45.             <!-- that no more elements need to be processed and that we       -->
  46.             <!-- return the maximum value instead of making any further     -->
  47.             <!-- recursive calls                                                        -->
  48.             <xsl:value-of select="$nMax" />
  49.         
  50.         </xsl:otherwise>        
  51.         </xsl:choose>
  52.     </xsl:template>
  53. </xsl:stylesheet>
  54.